<?xml version="1.0" encoding="utf-8"?>
<component>
    <?component error="false" debug="false"?>
    <registration description="fckeditor" progid="component.fckeditor" version="1.00" classid="{6BC39EC1-E62F-4884-9F30-DD6F1297083D}" />
    <public>
        <property name="version" />
        <property name="base" />
        <property name="instance" />
        <property name="width" />
        <property name="height" />
        <property name="toolbar" />
        <property name="value" />
        <property name="config" />
        <method name="create">
            <parameter name="instance" />
        </method>
    </public>
    <implements type="ASP" id="ASP"/>
    <script language="JScript" runat="server">
    <![CDATA[

        var version = '1.00';
        var base = '/fckeditor/';
        var instance = '';
        var width = '100%';
        var height = '200';
        var toolbar = 'default';
        var value = '';
        
        var config = Server.CreateObject('Scripting.Dictionary');
        
        function _compatible() {
            var _agent;
            _agent = String(Request.ServerVariables('HTTP_USER_AGENT'));
            var _version;
            
            if (_agent.indexOf('MSIE') > 0 && _agent.indexOf('mac') <= 0  && _agent.indexOf('Opera') <= 0) {
                _version = parseFloat(_format(_agent.substr(_agent.indexOf('MSIE') + 5, 3)));
                return _version >= 5.5;
            }
            else if (_agent.indexOf('Gecko/') > 0) {
                _version = parseInt(_agent.substr(_agent.indexOf('Gecko/') + 6, 8));
                return _version >= 20030210;
            }
            else if (_agent.indexOf('Opera/') > 0) {
                _version = parseFloat(_format(_agent.substr(_agent.indexOf('Opera/') + 6, 4)));
                return _version >= 9.5
            }
            else if (_agent.indexOf('AppleWebKit/') > 0) {
                var _matches = _agent.match(/AppleWebKit\/(\d+)/);
                return parseInt(_matches[1]) >= 522;
            }
            else {
                return false;
            }
        }

        function _format(string) {
            if (isNaN('5.5')) {
                return string.replace(',', '.')
            }
            else {
                return string.replace('.', ',')
            }
        }

        function _config() {
            var _params;
        
            var _first = true;

            for (var _key in config) {
                if (_first == false) {
                    _params += '&amp;';
                }
                else {
                    _first = false;
                }
            
                _params += _encode(_key) + '=' + _encode(config(_key))
            }
            
            return _params;
        }

        function _encode(value) {
            if (typeof value == 'boolean') {
                if (value == true) {
                    return true;
                }
                else {
                    return false;
                } 
            }
            else {
                return value.replace('&', '%26').replace('=', '%3D').replace('"', '%22');
            }                          
        }
        
        function create(instance) {
            instance = instance;
            Response.Write('<div>')

            if (_compatible()) {
                var _file;
                if (Request.QueryString('fcksource') == 'true') {
                    _file = "fckeditor.original.html";
                }
                else {
                    _file = "fckeditor.html";
                }

                var _link;
                _link = base + 'editor/' + _file + '?InstanceName=' + instance;
                
                if ((this.toolbar & '') != '') {
                    _link = _link + '&amp;Toolbar=' & toolbar;
                }

                Response.Write('<input type="hidden" id="' + instance + '" name="' + instance + '" value="' + Server.HTMLEncode(value) + '" style="display:none" />');
                Response.Write('<input type="hidden" id="' + instance + '___Config" value="' + _config() + '" style="display:none" />');
                Response.Write('<iframe id="' + instance + '___Frame" src="' + _link + '" width="' + width + '" height="' + height + '" frameborder="0" scrolling="no"></iframe>');

		        }
            else {
                var _width, _height;
                
                if (width.indexOf('%') > 0) {
                    _width = width;
                }
                else {
                    _width = width + 'px';
                }
                
                if (this.Height.indexOf('%') > 0) {
                    _height = height;
                }
                else {
                    _height = height + 'px';
                }

                Response.Write('<textarea name="' + instance + '" rows="4" cols="40" style="width: ' + _width + '; height: ' + _height + '">' + Server.HTMLEncode(value) + '</textarea>');
		        }

		        Response.Write('</div>');
        }
    ]]>
    </script>
</component>
